AppleScript allows you to automate routine tasks. VersaTile currently supports some basic AppleScripting. Future versions of VersaTile may extend AppleScript compatibility to provide recordable scripting and support for a wider range of events.
Since AppleScripting is not easy and by no means as intuitive as it should be. I will attempt to walk you through some basic scripts that will allow you to control VersaTile. You can copy these scripts into the Script Editor provided by Apple, make any changes you need as far as disk names, folder locations, etc. and then run them. As you become more familiar with AppleScripting you can extend these scripts to handle more sophisticated tasks.
Launching VersaTile using AppleScript
This is the first task you must master before you can begin to work with any of the other scripts. We have to figure out how to get VersaTile running if it isn't already. Note: you can use the same techniques discussed below to open other applications as well.
First we need to tell the script where to find the VersaTile application. Start your search at the name of the hard drive that contains the VersaTile Application. My hard drive is called "Power Macintosh". On the hard drive called "Power Macintosh" I have a folder at the root level which is called "VersaTile Folder" so I need to add that to my search path. I now have "Power Macintosh:VersaTile Folder:" as my search path, note the colon at the end of the names, be sure to include this at the end of all names which reference a disk or a folder. Inside the "VersaTile Folder" folder, is the VersaTile Pro application called "VersaTile Pro" so I add that to the search path to finally obtain "Power Macintosh:VersaTile Folder:VersaTile Pro"
Looks simple enough? I simply told the application to activate. If it isn't running, the Finder will open it for me. If it is running, the Finder will bring it to the front.
Now let's get a little more sophisticated. Because I change the name of my folders and move their locations quite often, it is inconvenient to go into my scripts and change every occurrence of the name in a search path. It is easy to set a couple of variables to the name of my hard drive, and folders, and then use the variable names when referring to these items. Don't be scared off by the term variable, you won't need to remember any high school algebra to do this.
Here's an example of the previous script, only now using variables:
Notice that I have set the variable DISKNAME to the name of my hard drive. I've set the variable FOLDERPATH to the folder name where VersaTile Pro is located, and finally set the
APPNAME variable to the name of the VersaTile application. You can use almost any name for your variables, just be sure to use them consistently throughout your script.
Now to active VersaTile Pro I simply tell application (DISKNAME & FOLDERPATH & APPNAME) to activate. The "&" symbol is used to concatenate the names together. The parentheses ensure that the concatenation of the names is completed before the application is
told to active.
The use of variable names in such a small script doesn't really gain you much. Think about when your scripts get longer and the name of your hard drives appears a hundred or so times.
Do you really want to change all hundred occurrences in the script? If you use variables like I did above, you simply change the name assigned to the variable to reflect the name of your new hard drive and you're finished.
Opening a VersaTile Palette
Now that we have learned how to open VersaTile, lets try opening a palette that was previously saved. To do this we will need to extend our previous script.
open { file (DISKNAME & FOLDERPATH & "Applications") }
end tell
This script will launch VersaTile and then open the palette called "Applications" which in the "VersaTile Folder". Can you begin to see how the use of variables will save us a lot of work later? Let's look at the new command that we added. The "open" statement tells VersaTile to open a file. The { } symbols are use to indicate a file list. The "file" statement let's VersaTile know that it is opening a file, instead of say a folder, or alias. And lastly comes our search path information contained in the parentheses.
If you understood what we've done up to this point then you move to the head of the class. If you are having difficulty, now would be a good time to go back and review.
Dynamically Adding Items to a Palette
Now comes the fun part, adding items to the palette we just opened. Actually the basics are fairly simple, we will use the "open" command again.
open { file (DISKNAME & FOLDERPATH & "Applications") }
open { file (DISKNAME & "System Folder:" & "Apple Menu Items:" & "Alarm Clock") }
end tell
The new open command adds the Alarm Clock desk accessory to the Applications palette we opened previously.
Now you can include an open command for each item you want to add to the palette, or you can all add all the files/folders within another folder or disk by extending the script even further. Below is an example on how do to this. This script is fairly complex so examine it carefully.
open {file (DISKNAME & FOLDERPATH & "Applications")}
set FILENUMBER to count LISTNAME
repeat with i from 1 to FILENUMBER
set FILENAME to (get item i of LISTNAME)
open {file (DISKNAME & FILENAME)}
end repeat
end tell
This script performs the same activation and palette opening tasks as the previous one, but now it adds all the files and folders located at the root level of my hard drive to the palette. Let's see how this works.
The new "set LISTNAME to list folder DISKNAME" creates a list of files and folders located at the root level of my hard drive.
The " set FILENUMBER to count LISTNAME" statement counts the number of items that are in the list LISTNAME. The variable FILENUMBER is then set to equal the number counted.
The "repeat with i from 1 to FILENUMBER" tells the script that I want to repeat the next commands using i as a counter initially set to 1, and increasing until i is equal to FILENUMBER. This will become clearer as we look at the commands that are being repeated.
Next the "set FILENAME to (get item i of LISTNAME )" command is executed. We have seen previously that "list folder DISKNAME" statement is used to make a list of all the items at the root level of my hard drive. The list might look something like this "( "System Folder", "VersaTile Folder", "Apple Extras", .... )"
The "get item i of LISTNAME" gets the ith element of the list. Remember I said that i is used as an increment counter initially set to 1? Well the first time the "set FILENAME to (get item i of LISTNAME)" is executed "get item i of LISTNAME" will get the first item in the list, the second time the command is executed it will get the second element in the list, an onward until the increment counter equals FILENUMBER then the repeat will end. The variable FILENAME is set to the name of the ith element each time.
Next "open {file (DISKNAME & FILENAME)}" adds each item in the list to the palette.
Finally the "end repeat" tells the script where the end of the repeating commands are.
Saving and Closing Palettes
Now that we have created a palette, let's save it and then close it. This is acutally pretty simple, we just need to add a few more lines to out script.
open {file (DISKNAME & FOLDERPATH & "Applications")}
set FILENUMBER to count LISTNAME
repeat with i from 1 to FILENUMBER
set FILENAME to (get item i of LISTNAME)
open {file (DISKNAME & FILENAME)}
end repeat
save {file (DISKNAME & FOLDERPATH & "Applications")}
close {file (DISKNAME & FOLDERPATH & "Applications")}
end tell
The save and close statements look like the open statement that we used to open the palette originally. Notice I put the save statement before the close statement? If I had neglected to save that palette before closing it, VersaTile would display the standard "Do you want to save this palette?" alert. Sine I want this process to be as automated as possible, without any interaction with the program be the user, I will save the palette first.
Well, I hope this gives you a few ideas on how to use AppleScript to automate routine tasks, create dynamic palettes, etc.